import { DeleteDto, IndexDto, ShowDto } from '@libs/common/dto';
import { ApiProperty, PartialType } from '@nestjs/swagger';
import {
  IsBoolean,
  IsDateString,
  IsEnum,
  IsNotEmpty,
  IsOptional,
} from 'class-validator';

import { Attendance } from '../entities/attendance.entity';

export class IndexAttendanceDto extends IndexDto<Attendance> {}

export class ShowAttendanceDto extends ShowDto {}

export class DeleteAttendanceDto extends DeleteDto {}

export class CreateAttendanceDto {}

export class UpdateAttendanceDto extends PartialType(CreateAttendanceDto) {
  @ApiProperty()
  @IsNotEmpty({ message: 'id 不能为空' })
  id: string;
}

export class FindAttendanceDto {
  workDate?: Date | string | number;
}

export class SyncAttendanceDto {
  @IsNotEmpty({ message: 'workDateFrom 不能为空' })
  workDateFrom: string;
  workDateTo?: string;
}

export class SwitchAttendanceDto {
  @ApiProperty()
  @IsNotEmpty({ message: 'id 不能为空' })
  id: string;

  @ApiProperty({ description: '状态' })
  @IsNotEmpty({ message: '状态不能为空' })
  @IsBoolean()
  status: boolean;
}

export class ImportAttendanceDto {}

export class ExportAttendanceDto {}

export const StatisticsAttendanceType = ['timeResult', 'sourceType'] as const;

export class StatisticsAttendanceDto {
  @IsNotEmpty({ message: 'dingId 不能为空' })
  dingId: string;

  @IsEnum(StatisticsAttendanceType, {
    message: `type 必须是 [${StatisticsAttendanceType.join('、')}] 之一`,
  })
  @IsNotEmpty()
  type: (typeof StatisticsAttendanceType)[number];

  @IsDateString()
  @IsOptional()
  start?: string;

  @IsDateString()
  @IsOptional()
  end?: string;
}

export class TodayAttendanceDto {
  workDate: string;
}
